package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
@ServletComponentScan
@SpringBootApplication
public class DemoApplication{

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
}
/**
 * 通过实现 ServletContextInitializer 接口直接注册
 * @author zmk
 */
/*@SpringBootApplication
public class DemoApplication implements ServletContextInitializer{

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		servletContext.addServlet("commonServlet", new CommonServlet()).addMapping("/servlet");
		servletContext.addFilter("commonFilter", new CommonFilter())
					  .addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, "commonServlet");
		servletContext.addListener(new CommonListener());
	}
}*/

/**
 * 第一种注册bean的形式
 * @author zmk
 */
    /*@SpringBootApplication
    public class DemoApplication {
 
	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
	@Bean
	public ServletRegistrationBean<CommonServlet> servletRegistrationBean() {
		//  /*匹配所有的请求路径
		return new ServletRegistrationBean<CommonServlet>(new CommonServlet(), "/servlet");
	}

	@Bean
	public FilterRegistrationBean<CommonFilter> filterRegistrationBean() {
		return new FilterRegistrationBean<CommonFilter>(new CommonFilter(), servletRegistrationBean());
	}

	@Bean
	public ServletListenerRegistrationBean<CommonListener> servletListenerRegistrationBean() {
		return new ServletListenerRegistrationBean<CommonListener>(new CommonListener());
	}
}
*/